# -*- coding: utf-8 -*-
# !/usr/bin/env python3
# Author: eddyhhu(胡皓)
import os


class BaseConfig:
    # server config
    SERVER_CONFIG = {
        "host": "127.0.0.1",
        "port": 8001,
        "reload": True
    }
    # fastapi app config
    app_config = {
        "title": "Tortoise ORM FastAPI example"
    }
    # mysql config
    DB = {
        "master": {
            "host": "127.0.0.1",
            "port": 3306,
            "user": 'root',
            "password": '1012442045',
            "database": 'fastapi_demo',
            "charset": "utf8"
        },
        # "slave": {
        #     "host": "127.0.0.1",
        #     "port": 3306,
        #     "user": 'root',
        #     "password": '1012442045',
        #     "database": 'fastapi_demo',
        #     "charset": "utf8"
        # }
    }
    db_url_master = "mysql://{user}:{password}@{host}:{port}/{database}?charset={charset}".format(**DB["master"])
    # db_url_slave = "mysql://{user}:{password}@{host}:{port}/{database}?charset={charset}".format(**DB["slave"])
    TORTOISE_DB_CONFIG = {
        'connections': {
            # Dict format for connection
            # 'default': {
            #     'engine': 'tortoise.backends.mysql',
            #     'credentials': {
            #         'host': 'localhost',
            #         'port': '5432',
            #         'user': 'tortoise',
            #         'password': 'qwerty123',
            #         'database': 'test',
            #     }
            # },
            'default': db_url_master
        },
        'apps': {
            'models': {
                'models': ['__main__'],
                'default_connection': 'default',
            }
        }
    }
    # log config
    log_config = {
        "when": "D",
        "interval": 1,
        "backupCount": 10
    }
    LOG_FORMAT = ("[%(asctime)s] [PID %(process)d] [%(threadName)s] "
                  "[%(module)s.%(funcName)s:%(lineno)s] [%(levelname)s] %(message)s")
    FILE_PATH = "./logs/demo.log"


class TestConfig(BaseConfig):
    pass


class LocalConfig(BaseConfig):
    pass


class DevConfig(BaseConfig):
    pass


class ProdConfig(BaseConfig):
    pass


env_config = {
    "local": LocalConfig,
    "test": TestConfig,
    "dev": DevConfig,
    "prod": ProdConfig,
}
env = os.environ.get("fastapi-demo")
if not env:
    config = LocalConfig()
else:
    config = env_config[env]()
